package com.yh.csx.crm.vo;

import com.yh.csx.crm.po.SysSalesPermission;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Huang Zhaoping
 * @date 2019/4/16
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PermissionVo {

    private List<SysSalesPermission> permissions;

    public boolean isPermitAll() {
        return permissions == null || permissions.size() == 0;
    }

    public List<Long> getUserIds() {
        if (isPermitAll()) return null;
        return permissions.stream().map(SysSalesPermission::getUserId).collect(Collectors.toList());
    }

    public List<String> getWorkNumbers() {
        if (isPermitAll()) return null;
        return permissions.stream().map(s -> StringUtils.isBlank(s.getWorkNumber()) ? String.valueOf(s.getUserId()) : s.getWorkNumber()).collect(Collectors.toList());
    }
}
